package cn.jisol.ngame;

import com.alibaba.fastjson.JSON;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;

public class GameDemo extends SimpleApplication {
    private BulletAppState bulletAppState;
    private static final Geometry box;

    static {
        Box b = new Box(1, 1, 1);
        box = new Geometry("Box", b);
    }

    public static void main(String[] args) {

        GameDemo app = new GameDemo();

        AppSettings settings = new AppSettings(true);
        settings.setTitle("My Awesome Game");
        app.setSettings(settings);
        app.start(JmeContext.Type.Headless);
//        app.start();

    }

    @Override
    public void simpleInitApp() {

        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);

        RigidBodyControl brick_phy = new RigidBodyControl(2f);
        box.addControl(brick_phy);
        bulletAppState.getPhysicsSpace().add(brick_phy);

//        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//        mat.setColor("Color", ColorRGBA.Blue);
//        geom.setMaterial(mat);

        rootNode.attachChild(box);

    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
        System.out.println(tpf);
        bulletAppState.update(tpf);
        System.out.println(JSON.toJSONString(box.getLocalTransform().getTranslation()));
    }

}
